<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>
    const arr = [1,8,6,2,5,4,8,3,7]
    // const lengthArr=[]
    let max = 0
    for(let i = 0; i < arr.length; i++){
      for(let j = arr.length-1; j > i; j--){
        // max = Math.min(arr[i],arr[j])*(j-i) > max? Math.min(arr[i],arr[j])*(j-i) : max
          //  lengthArr.push(Math.min(arr[i],arr[j])*(j-i))
          max = Math.max(Math.min(arr[i],arr[j])*(j-i) , max)
      }
    }
    // const num = Math.max(...lengthArr)
    // console.log(lengthArr);
    // console.log(num);
    console.log(max);
  </script>
</body>
</html>